package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;

public class SPLIT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 2)
      return Primitive.ERROR_NAME;
    String str1 = paramArrayOfObject[0].toString();
    String str2 = paramArrayOfObject[1].toString();
    return new FArray(str1.split(str2));
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "SPLIT(String1,String2)：返回由String2分割String1组成的字符串数组。\nString1：以双引号表示的字符串。\nString2：以双引号表示的分隔符。例如逗号\",\"\n示例:\nSPLIT(\"hello,world,yes\",\",\") = [\"hello\",\"world\",\"yes\"]。\nSPLIT(\"this is very good\",\" \") = [\"this\",\"is\",\"very\",\"good\"]。\n备注：\n如果只有一个参数，则返回一个错误。\n如果有多个参数，则只有前两个起作用。";
  }

  public String getEN()
  {
    return "SPLIT(String1,String2)：return an array that is the composition of the result that String1 is split by String2. \nString1: a string of characters that is between double quotes.\nString2: a string of characters that is between double quotes.\nExample: \nSPLIT(\"hello,world\",\",\") = [\"hello\",\"world\"].\nSPLIT(\"this is very good\",\" \") = [\"this\",\"is\",\"very\",\"good\"].\nRemarks:\n1. if there is only one parameter, then SPLIT will return an error.\n2. If there are more than two parameters, only the first two works.";
  }
}